package com.huaxin.hxmoduleworkorder.event;

import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderElectricianTaskStatus;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderOperatorRole;
import org.springframework.context.ApplicationEvent;

import java.time.Instant;

public final class MaintenanceOrderElectricianTaskStatusChangedEvent extends ApplicationEvent {

    private final String taskId;
    private final MaintenanceOrderElectricianTaskStatus oldStatus;
    private final MaintenanceOrderElectricianTaskStatus newStatus;
    private final String operatorId;
    private final MaintenanceOrderOperatorRole operatorRole;
    private final Instant timestamp;

    // 私有构造，仅允许通过静态工厂创建
    private MaintenanceOrderElectricianTaskStatusChangedEvent(Object source,
                                                              String taskId,
                                                              MaintenanceOrderElectricianTaskStatus oldStatus,
                                                              MaintenanceOrderElectricianTaskStatus newStatus,
                                                              String operatorId,
                                                              MaintenanceOrderOperatorRole operatorRole,
                                                              Instant timestamp) {
        super(source);
        this.taskId = taskId;
        this.oldStatus = oldStatus;
        this.newStatus = newStatus;
        this.operatorId = operatorId;
        this.operatorRole = operatorRole;
        this.timestamp = timestamp;
    }

    // ---------------- Getters ----------------
    public String getTaskId() {
        return taskId;
    }

    public MaintenanceOrderElectricianTaskStatus getOldStatus() {
        return oldStatus;
    }

    public MaintenanceOrderElectricianTaskStatus getNewStatus() {
        return newStatus;
    }

    public String getOperatorId() {
        return operatorId;
    }

    public MaintenanceOrderOperatorRole getOperatorRole() {
        return operatorRole;
    }

    // ✅ 静态工厂方法（public）
    public static MaintenanceOrderElectricianTaskStatusChangedEvent of(
            Object source,
            String orderId,
            MaintenanceOrderElectricianTaskStatus oldStatus,
            MaintenanceOrderElectricianTaskStatus newStatus,
            String operatorId,
            MaintenanceOrderOperatorRole operatorRole) {
        return new MaintenanceOrderElectricianTaskStatusChangedEvent(
                source, orderId, oldStatus, newStatus, operatorId, operatorRole, Instant.now());
    }
}